<?php
/**
 * Shop page WooCommerce Booster Module
 *
 * @package WooCommerce Booster
 */

namespace Neve_Pro\Modules\Woocommerce_Booster\Customizer;

use Neve\Customizer\Base_Customizer;
use Neve\Customizer\Types\Control;

/**
 * Class Shop_Page
 *
 * @package Neve_Pro\Modules\Woocommerce_Booster\Customizer
 */
class Shop_Page extends Base_Customizer {

	/**
	 * Init function sooner than WooCommerce.
	 */
	public function init() {
		add_action( 'customize_register', array( $this, 'register_controls_callback' ), 9 );
		add_filter( 'neve_last_menu_item_components', array( $this, 'add_wish_list_menu_option' ) );
		add_filter( 'neve_sidebar_layout_choices', array( $this, 'add_off_canvas_option' ), 10, 2 );
		add_action( 'customize_controls_print_styles', array( $this, 'elements_ordering_inline_alignment_style' ) );
		add_action( 'customize_controls_print_scripts', array( $this, 'elements_ordering_inline_alignment_script' ) );
	}

	/**
	 * Hide price in Card content elements order in customizer.
	 */
	public function elements_ordering_inline_alignment_style() {
		$alignment = get_theme_mod( 'neve_product_content_alignment', 'left' );
		if ( $alignment !== 'inline' ) {
			return false;
		}
		echo '<style>';
		echo '#customize-control-neve_layout_product_elements_order .order-component[data-id="price"] { display: none; }';
		echo '</style>';

		return true;
	}

	/**
	 * Handle the customizer display when alignment settings are changing.
	 */
	public function elements_ordering_inline_alignment_script() {
		?>
		<script type="text/javascript">
			jQuery(document).ready(function () {
				wp.customize.bind('ready', function () {
					var value = wp.customize('neve_product_content_alignment').get();
						if (value === 'inline') {
							jQuery('#customize-control-neve_layout_product_elements_order .order-component[data-id="title"]').find('p').text('<?php echo esc_html__( 'Title + Price', 'neve' ); ?>');
						}
				});

				wp.customize('neve_product_content_alignment', function (value) {
					value.bind(function (newval) {
						if (newval !== 'inline') {
							jQuery('#customize-control-neve_layout_product_elements_order .order-component[data-id="title"]').find('p').text('<?php echo esc_html__( 'Title', 'neve' ); ?>');
							jQuery('#customize-control-neve_layout_product_elements_order .order-component[data-id="price"]').css('display', 'flex');
						}
						if (newval === 'inline') {
							jQuery('#customize-control-neve_layout_product_elements_order .order-component[data-id="title"]').find('p').text('<?php echo esc_html__( 'Title + Price', 'neve' ); ?>');
							jQuery('#customize-control-neve_layout_product_elements_order .order-component[data-id="price"]').hide();
						}
					});
				});
			});
		</script>
		<?php
	}

	/**
	 * Add wish list item in last menu items options.
	 *
	 * @param array $items Last menu items options.
	 *
	 * @return mixed
	 */
	public function add_wish_list_menu_option( $items ) {
		$items['wish_list'] = __( 'Wish List', 'neve' );

		return $items;
	}

	/**
	 * Add customizer controls.
	 */
	public function add_controls() {
		$this->group_controls();
		$this->add_page_layout_controls();
		$this->add_product_card_layout_controls();
		$this->add_card_image_controls();
		$this->add_card_content_controls();
		$this->add_sale_tag_controls();
	}

	/**
	 * Add control groups to better organize the customizer.
	 */
	private function group_controls() {
		$this->add_control(
			new Control(
				'neve_woo_shop_settings_heading',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => $this->selective_refresh,
				),
				array(
					'label'            => esc_html__( 'General', 'neve' ),
					'section'          => 'woocommerce_product_catalog',
					'priority'         => 0,
					'class'            => 'woo-shop-accordion',
					'accordion'        => true,
					'controls_to_wrap' => 3,
					'expanded'         => true,
				),
				'Neve\Customizer\Controls\Heading'
			)
		);

		$this->add_control(
			new Control(
				'neve_shop_page_layout_ui_heading',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => $this->selective_refresh,
				),
				array(
					'label'            => esc_html__( 'Page Layout', 'neve' ),
					'section'          => 'woocommerce_product_catalog',
					'priority'         => 100,
					'class'            => 'page-layout-accordion',
					'accordion'        => true,
					'controls_to_wrap' => 5,
					'expanded'         => true,
				),
				'Neve\Customizer\Controls\Heading'
			)
		);

		$this->add_control(
			new Control(
				'neve_product_card_layout_ui_heading',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => $this->selective_refresh,
				),
				array(
					'label'            => esc_html__( 'Product Card', 'neve' ),
					'section'          => 'woocommerce_product_catalog',
					'priority'         => 200,
					'class'            => 'card-layout-accordion',
					'accordion'        => true,
					'controls_to_wrap' => 5,
					'expanded'         => false,
				),
				'Neve\Customizer\Controls\Heading'
			)
		);

		$this->add_control(
			new Control(
				'neve_card_image_ui_heading',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => $this->selective_refresh,
				),
				array(
					'label'            => esc_html__( 'Card Image', 'neve' ),
					'section'          => 'woocommerce_product_catalog',
					'priority'         => 300,
					'class'            => 'card-image-accordion',
					'accordion'        => true,
					'controls_to_wrap' => 3,
					'expanded'         => false,
				),
				'Neve\Customizer\Controls\Heading'
			)
		);

		$this->add_control(
			new Control(
				'neve_card_content_ui_heading',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => $this->selective_refresh,
				),
				array(
					'label'            => esc_html__( 'Card Content', 'neve' ),
					'section'          => 'woocommerce_product_catalog',
					'priority'         => 400,
					'class'            => 'card-content-accordion',
					'accordion'        => true,
					'controls_to_wrap' => 3,
					'expanded'         => false,
				),
				'Neve\Customizer\Controls\Heading'
			)
		);

		$this->add_control(
			new Control(
				'neve_sale_tag_ui_heading',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => $this->selective_refresh,
				),
				array(
					'label'            => esc_html__( 'Sale Tag', 'neve' ),
					'section'          => 'woocommerce_product_catalog',
					'priority'         => 500,
					'class'            => 'sale-tag-accordion',
					'accordion'        => true,
					'controls_to_wrap' => 8,
					'expanded'         => false,
				),
				'Neve\Customizer\Controls\Heading'
			)
		);
	}

	/**
	 * Controls that refer to page layout.
	 */
	private function add_page_layout_controls() {
		$this->add_control(
			new Control(
				'neve_products_per_row',
				array(
					'sanitize_callback' => 'neve_sanitize_range_value',
					'default'           => json_encode(
						array(
							'desktop' => 4,
							'tablet'  => 2,
							'mobile'  => 2,
						)
					),
				),
				array(
					'label'           => esc_html__( 'Products per row', 'neve' ),
					'section'         => 'woocommerce_product_catalog',
					'units'           => array(
						'items',
					),
					'input_attr'      => array(
						'mobile'  => array(
							'min'     => 1,
							'max'     => 6,
							'default' => 1,
						),
						'tablet'  => array(
							'min'     => 1,
							'max'     => 6,
							'default' => 2,
						),
						'desktop' => array(
							'min'     => 1,
							'max'     => 6,
							'default' => 4,
						),
					),
					'input_attrs'     => [
						'step'       => 1,
						'min'        => 1,
						'max'        => 6,
						'defaultVal' => [
							'mobile'  => 1,
							'tablet'  => 2,
							'desktop' => 4,
						],
					],
					'priority'        => 110,
					'responsive'      => true,
					'active_callback' => array( $this, 'products_per_row_active_callback' ),
				),
				version_compare( NEVE_VERSION, '2.6.3', '>=' ) ? 'Neve\Customizer\Controls\React\Responsive_Range' : 'Neve\Customizer\Controls\Responsive_Number'
			)
		);

		$rows    = get_theme_mod( 'woocommerce_catalog_rows' );
		$cols    = get_theme_mod( 'woocommerce_catalog_columns' );
		$default = ( $rows * $cols ) > 0 ? $rows * $cols : 12;
		$this->add_control(
			new Control(
				'neve_products_per_page',
				array(
					'default' => $default,
				),
				array(
					'label'       => esc_html__( 'Products per page', 'neve' ),
					'section'     => 'woocommerce_product_catalog',
					'priority'    => 120,
					'type'        => 'number',
					'input_attrs' => array(
						'min'  => 1,
						'step' => 1,
					),
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_shop_pagination_type',
				array(
					'default'           => 'number',
					'sanitize_callback' => array( $this, 'sanitize_pagination_type' ),
				),
				array(
					'label'    => esc_html__( 'Pagination', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 130,
					'type'     => 'select',
					'choices'  => array(
						'number'   => esc_html__( 'Number', 'neve' ),
						'infinite' => esc_html__( 'Infinite Scroll', 'neve' ),
					),
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_enable_product_filter',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => true,
				),
				array(
					'label'    => esc_html__( 'Products filtering', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'type'     => 'neve_toggle_control',
					'priority' => 140,
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_enable_product_layout_toggle',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				),
				array(
					'label'    => esc_html__( 'Layout toggle', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'type'     => 'neve_toggle_control',
					'priority' => 150,
				)
			)
		);
	}

	/**
	 * Controls that refer to produt card layout.
	 */
	private function add_product_card_layout_controls() {

		$this->add_control(
			new Control(
				'neve_product_card_layout',
				array(
					'default'           => 'grid',
					'sanitize_callback' => array( $this, 'sanitize_shop_layout' ),
				),
				array(
					'label'    => esc_html__( 'Layout', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 210,
					'choices'  => array(
						'grid' => array(
							'url' => '',
						),
						'list' => array(
							'url' => '',
						),
					),
				),
				'Neve\Customizer\Controls\Radio_Image'
			)
		);

		$this->add_control(
			new Control(
				'neve_box_shadow_intensity',
				array(
					'sanitize_callback' => 'absint',
					'default'           => 0,
				),
				array(
					'label'       => esc_html__( 'Box shadow (px)', 'neve' ),
					'section'     => 'woocommerce_product_catalog',
					'type'        => 'neve_range_control',
					'step'        => 1,
					'input_attrs' => array(
						'min'        => 0,
						'max'        => 30,
						'defaultVal' => 0,
					),
					'priority'    => 220,
				),
				class_exists( 'Neve\Customizer\Controls\React\Range' ) ? 'Neve\Customizer\Controls\React\Range' : 'Neve\Customizer\Controls\Range'
			)
		);

		$this->add_control(
			new Control(
				'neve_add_to_cart_display',
				array(
					'default'           => 'none',
					'sanitize_callback' => array( $this, 'sanitize_add_to_cart_display' ),
				),
				array(
					'label'    => esc_html__( 'Add to Cart Button', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 230,
					'choices'  => array(
						'none'     => array(
							'url' => '',
						),
						'after'    => array(
							'url' => '',
						),
						'on_image' => array(
							'url' => '',
						),
					),
				),
				'Neve\Customizer\Controls\Radio_Image'
			)
		);

		$this->add_control(
			new Control(
				'neve_quick_view',
				array(
					'default'           => 'none',
					'sanitize_callback' => array( $this, 'sanitize_button_position' ),
				),
				array(
					'label'    => esc_html__( 'Quick view', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 240,
					'choices'  => array(
						'none'   => array(
							'url' => '',
						),
						'top'    => array(
							'url' => '',
						),
						'bottom' => array(
							'url' => '',
						),
					),
				),
				'Neve\Customizer\Controls\Radio_Image'
			)
		);

		$this->add_control(
			new Control(
				'neve_wish_list',
				array(
					'default'           => 'none',
					'sanitize_callback' => array( $this, 'sanitize_button_position' ),
				),
				array(
					'label'    => esc_html__( 'Wish List', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 250,
					'choices'  => array(
						'none'   => array(
							'url' => '',
						),
						'top'    => array(
							'url' => '',
						),
						'bottom' => array(
							'url' => '',
						),
					),
				),
				'Neve\Customizer\Controls\Radio_Image'
			)
		);
	}

	/**
	 * Controls that change the way that product image looks.
	 */
	private function add_card_image_controls() {

		$this->add_control(
			new Control(
				'neve_force_same_image_height',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				),
				array(
					'label'    => esc_html__( 'Force Same Image Height', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'type'     => 'neve_toggle_control',
					'priority' => 310,
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_image_height',
				array(
					'sanitize_callback' => 'absint',
					'default'           => 230,
				),
				array(
					'label'           => esc_html__( 'Image height (px)', 'neve' ),
					'section'         => 'woocommerce_product_catalog',
					'step'            => 1,
					'input_attrs'     => array(
						'min'        => 100,
						'max'        => 500,
						'defaultVal' => 230,
					),
					'priority'        => 320,
					'active_callback' => array( $this, 'same_image_height_active_callback' ),
				),
				class_exists( 'Neve\Customizer\Controls\React\Range' ) ? 'Neve\Customizer\Controls\React\Range' : 'Neve\Customizer\Controls\Range'
			)
		);

		$this->add_control(
			new Control(
				'neve_image_hover',
				array(
					'default'           => 'none',
					'sanitize_callback' => array( $this, 'sanitize_image_hover' ),
				),
				array(
					'label'    => esc_html__( 'Image style', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 330,
					'type'     => 'select',
					'choices'  => array(
						'none'      => esc_html__( 'None', 'neve' ),
						'zoom'      => esc_html__( 'Zoom', 'neve' ),
						'swipe'     => esc_html__( 'Swipe Next Image', 'neve' ),
						'blur'      => esc_html__( 'Blur', 'neve' ),
						'fadein'    => esc_html__( 'Fade In', 'neve' ),
						'fadeout'   => esc_html__( 'Fade Out', 'neve' ),
						'glow'      => esc_html__( 'Glow', 'neve' ),
						'colorize'  => esc_html__( 'Colorize', 'neve' ),
						'grayscale' => esc_html__( 'Grayscale', 'neve' ),
					),
				)
			)
		);
	}

	/**
	 * Controls for card content.
	 */
	private function add_card_content_controls() {

		$order_default_components = array(
			'title',
			'reviews',
			'price',
		);

		$components = array(
			'category'          => __( 'Category', 'neve' ),
			'title'             => __( 'Title', 'neve' ),
			'short-description' => __( 'Short description', 'neve' ),
			'reviews'           => __( 'Reviews', 'neve' ),
			'price'             => __( 'Price', 'neve' ),
		);

		$this->add_control(
			new Control(
				'neve_layout_product_elements_order',
				array(
					'sanitize_callback' => array( $this, 'sanitize_product_elements_ordering' ),
					'default'           => json_encode( $order_default_components ),
				),
				array(
					'label'      => esc_html__( 'Elements Order', 'neve' ),
					'section'    => 'woocommerce_product_catalog',
					'type'       => 'ordering',
					'components' => $components,
					'priority'   => 410,
				),
				'Neve\Customizer\Controls\Ordering'
			)
		);

		$this->add_control(
			new Control(
				'neve_product_content_alignment',
				array(
					'default'           => 'left',
					'sanitize_callback' => array( $this, 'sanitize_product_content_alignment' ),
				),
				array(
					'label'    => esc_html__( 'Alignment', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 420,
					'choices'  => array(
						'left'   => array(
							'url' => '',
						),
						'center' => array(
							'url' => '',
						),
						'right'  => array(
							'url' => '',
						),
						'inline' => array(
							'url' => '',
						),
					),
				),
				'Neve\Customizer\Controls\Radio_Image'
			)
		);

		$this->add_control(
			new Control(
				'neve_advanced_reviews',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				),
				array(
					'label'    => esc_html__( 'Advanced reviews', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'type'     => 'neve_toggle_control',
					'priority' => 430,
				)
			)
		);
	}

	/**
	 * Add sale tag customizer controls.
	 */
	private function add_sale_tag_controls() {

		$this->add_control(
			new Control(
				'neve_sale_tag_position',
				array(
					'default'           => 'inside',
					'sanitize_callback' => array( $this, 'sanitize_sale_tag_position' ),
				),
				array(
					'label'    => esc_html__( 'Position', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 510,
					'choices'  => array(
						'inside'  => array(
							'url' => '',
						),
						'outside' => array(
							'url' => '',
						),
					),
				),
				'Neve\Customizer\Controls\Radio_Image'
			)
		);

		$this->add_control(
			new Control(
				'neve_sale_tag_alignment',
				array(
					'default'           => 'left',
					'sanitize_callback' => array( $this, 'sanitize_sale_tag_alignment' ),
				),
				array(
					'label'    => esc_html__( 'Alignment', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 520,
					'type'     => 'select',
					'choices'  => array(
						'left'  => esc_html__( 'Left', 'neve' ),
						'right' => esc_html__( 'Right', 'neve' ),
					),
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_sale_tag_radius',
				array(
					'sanitize_callback' => 'absint',
					'default'           => 0,
				),
				array(
					'label'       => esc_html__( 'Border radius (%)', 'neve' ),
					'section'     => 'woocommerce_product_catalog',
					'type'        => 'neve_range_control',
					'step'        => 1,
					'input_attr'  => array(
						'min'     => 0,
						'max'     => 50,
						'default' => 0,
					),
					'input_attrs' => array(
						'min'        => 0,
						'max'        => 50,
						'defaultVal' => 0,
					),
					'priority'    => 530,
				),
				class_exists( 'Neve\Customizer\Controls\React\Range' ) ? 'Neve\Customizer\Controls\React\Range' : 'Neve\Customizer\Controls\Range'
			)
		);

		$this->add_control(
			new Control(
				'neve_sale_tag_text',
				array(
					'sanitize_callback' => 'sanitize_text_field',
				),
				array(
					'label'    => esc_html__( 'Text', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'priority' => 540,
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_enable_sale_percentage',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				),
				array(
					'label'    => esc_html__( 'Enable sale percentage', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'type'     => 'neve_toggle_control',
					'priority' => 550,
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_sale_percentage_format',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'default'           => '{value}%',
				),
				array(
					'label'           => esc_html__( 'Sale tag format', 'neve' ),
					'description'     => esc_html__( 'How the discount should be displayed. e.g. {value}%', 'neve' ),
					'section'         => 'woocommerce_product_catalog',
					'type'            => 'text',
					'priority'        => 555,
					'active_callback' => array( $this, 'neve_sale_percentage_format_active_callback' ),
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_sale_tag_color',
				array(
					'sanitize_callback' => 'neve_sanitize_colors',
					'default'           => '#2dce89',
				),
				array(
					'label'    => esc_html__( 'Background Color', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'type'     => 'neve_color_control',
					'priority' => 560,
				)
			)
		);

		$this->add_control(
			new Control(
				'neve_sale_tag_text_color',
				array(
					'sanitize_callback' => 'neve_sanitize_colors',
					'default'           => '#ffffff',
				),
				array(
					'label'    => esc_html__( 'Text Color', 'neve' ),
					'section'  => 'woocommerce_product_catalog',
					'type'     => 'neve_color_control',
					'priority' => 570,
				)
			)
		);
	}

	/**
	 * Sanitize the shop layout value.
	 *
	 * @param string $value Value from the control.
	 *
	 * @return bool
	 */
	public function sanitize_shop_layout( $value ) {
		$allowed_values = array( 'list', 'grid' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'grid';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize the pagination type
	 *
	 * @param string $value value from the control.
	 *
	 * @return bool
	 */
	public function sanitize_pagination_type( $value ) {
		$allowed_values = array( 'number', 'infinite' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'number';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize add to cart position control.
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_add_to_cart_display( $value ) {
		$allowed_values = array( 'none', 'after', 'on_image' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'number';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize content order control.
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_product_elements_ordering( $value ) {
		$allowed = array(
			'category',
			'title',
			'short-description',
			'reviews',
			'price',
		);

		if ( empty( $value ) ) {
			return json_encode( $allowed );
		}

		$decoded = json_decode( $value, true );

		foreach ( $decoded as $val ) {
			if ( ! in_array( $val, $allowed, true ) ) {
				return json_encode( $allowed );
			}
		}

		return $value;
	}

	/**
	 * Sanitize button position.
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_button_position( $value ) {
		$allowed_values = array( 'none', 'top', 'bottom' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'none';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize sale bubble position.
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_sale_tag_position( $value ) {
		$allowed_values = array( 'inside', 'outside' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'inside';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize sale tag alignment.
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_sale_tag_alignment( $value ) {
		$allowed_values = array( 'left', 'right' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'left';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize product content alignment.
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_product_content_alignment( $value ) {
		$allowed_values = array( 'left', 'right', 'center', 'inline' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'left';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize image hover control.
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_image_hover( $value ) {
		$allowed_values = array(
			'none',
			'swipe',
			'zoom',
			'blur',
			'fadein',
			'fadeout',
			'glow',
			'colorize',
			'grayscale',
		);
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'none';
		}

		return esc_html( $value );
	}

	/**
	 * Decide if image height control should be visible based on Force Same Image Height control.
	 *
	 * @return bool
	 */
	public function same_image_height_active_callback() {
		return get_theme_mod( 'neve_force_same_image_height' );
	}

	/**
	 * Decide if products per row should be visible based on Layout control.
	 *
	 * @return bool
	 */
	public function products_per_row_active_callback() {
		$layout_toggle = get_theme_mod( 'neve_enable_product_layout_toggle', false );
		if ( $layout_toggle === true ) {
			return true;
		}

		return get_theme_mod( 'neve_product_card_layout', 'grid' ) === 'grid';
	}

	/**
	 * Add off canvas option for shop layout.
	 *
	 * @param array  $current_settings Current control settings.
	 * @param string $control_id Current control id.
	 *
	 * @return array
	 */
	public function add_off_canvas_option( $current_settings, $control_id ) {
		if ( $control_id !== 'neve_shop_archive_sidebar_layout' ) {
			return $current_settings;
		}
		$current_settings['off-canvas'] = array(
			'url' => '',
		);

		return $current_settings;
	}

	/**
	 * Active callback for sale percentage format control
	 *
	 * @return bool
	 */
	public function neve_sale_percentage_format_active_callback() {
		return get_theme_mod( 'neve_enable_sale_percentage', false ) === true;
	}

}
